[#ftl]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>[#assign module]completcfg/${item.scope.id}/cpconfigs[/#assign][#assign moduleName="模块参数配置"]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="${base}/commonjs/flexgrid/css/flexigrid.pack.css" />

<script type="text/javascript" src="${base}/commonjs/jquery1.7.2/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="${base}/commonjs/flexgrid/js/flexigrid.js"></script>
<script type="text/javascript" src="${base}/commonjs/flexgrid/js/myflexigrid.js"></script>
<script type="text/javascript" src="${base}/commonjs/artDialog4/artDialog.source.js?skin=blue"></script>
<script type="text/javascript" src="${base}/commonjs/artDialog4/plugins/iframeTools.source.js"></script>
<title>${moduleName}列表</title>
</head>
<body>
<table class="flexme3" style="display: none"></table>
<script type="text/javascript">
var grid = $(".flexme3").flexigrid(generateFlexGridCfg({
  title:'${moduleName}列表',
  url : '${base}/${module}/all',
  dataType : 'json',
  singleSelect: true,
  colModel:[
    ["ID", "id", 40, true, "asc",  "left", null],
    ["名称", "name", 80, true, "",  "left", null],
    ["描述", "description", 100, true, "",  "left", null],
    ["描述符", "key", 70, false, "",  "left", null],
    ["别名", "alias", 70, false, "",  "left", null],
    ["类型", "type", 40, false, "",  "left", function(data){
    	return ["字符串","整数","实数","布尔","日期",][+data];
    }],
    ["来源", "source", 40, false, "",  "left", function(data){
    	data = +data||0;
    	return ["自动","配置值","请求参数","路径参数","标签配置",][data];
    }],
    ["参数值", "value", 60, false, "",  "left", null],
    ["原始值", "old", 60, false, "",  "left", null],
    ["Operation", "description", 100, false, "",  "left", function(data, id, rowData){
    	var id=+rowData[0];
    	var alias = rowData[4]||rowData[3];
    	var value = rowData[7]||rowData[8];
    	var src = rowData[6];
        var ops = ['<a href="javascript:customizeParam('+id+', \''+alias+'\', \''+value+'\', '+src+')">编辑</a>'];
        if(+id>0){
            ops.push('<a href="javascript:restoreParam('+id+')">恢复</a>');
        }
      return ops.join(" ");
    }]
  ],
  buttons: [
    //["添加${moduleName}", "add", addItem],
  ]
}));
function $1(id){
  return $("#"+id).val()
}
function flexGridReload(selector){
  $(selector).flexReload();
}

var dlg;
function restoreParam(id){
  dlg = art.dialog({
    content: "确定撤销新的参数值配置吗？该参数将使用原始值作为配置。",
    title: "恢复参数值",
    icon: "question",
    background: '#EEE', // 背景色
    opacity: 0.05,  // 透明度
    lock: true,
    button: [{
      name: "确定",
      callback: function(){
        $.post("${base}/${module}/"+id+"/restore.do", {}, function(text){
          var result = text;
          if(result.success){
            dlg.close();
            flexGridReload(".flexme3");
          }else{
            art.dialog({
            title: "删除失败",
            icon: "error",
            content: result.err,
            width: 400,
            height: 250,
            background: '#EEE', // 背景色
            opacity: 0.05,  // 透明度
            lock: true,
            ok: true
            });
          }
        });
        return false;
      }
    }, {
      name: "取消",
      focus: true
    }]
  });
}
function customizeParam(id, key, old, src){
  src=+src||0;
  var sb = ["请输入新的参数别名:<br><input type='text' id='input_alias' value='"+key+"'><br>",
            "请输入新的参数值:<br><input type='text' id='input_new' value='"+old+"'><br>",
            "数据来源：<br><select id='select_source'>",
            "<option value='0'",(src==0?" selected":""),">自动",
            "<option value='1'",(src==1?" selected":""),">配置值",
            "<option value='2'",(src==2?" selected":""),">请求参数",
            "<option value='3'",(src==3?" selected":""),">路径参数",
            "<option value='4'",(src==4?" selected":""),">标签配置",
            "</select>"];
  dlg = art.dialog({
    content: sb.join(""),
    title: "配置参数值",
    icon: "question",
    background: '#EEE', // 背景色
    opacity: 0.05,  // 透明度
    lock: true,
    button: [{
      name: "确定",
      callback: function(){
        var value = $("#input_new").val();
        var alias = $("#input_alias").val();
        var source = $("#select_source").val();
        $.post("${base}/${module}/"+id+"/edit", {value: encodeURIComponent(value), alias: encodeURIComponent(alias), source: source}, function(text){
          var result = text;
          if(result.success){
            dlg.close();
            flexGridReload(".flexme3");
          }else{
            art.dialog({
            title: "删除失败",
            icon: "error",
            content: result.err,
            width: 400,
            height: 250,
            background: '#EEE', // 背景色
            opacity: 0.05,  // 透明度
            lock: true,
            ok: true
            });
          }
        });
        return false;
      }
    }, {
      name: "取消",
      focus: true
    }]
  });
}

</script>

</body>
</html>